package com.leyou.order.listener;


import com.leyou.common.constants.RocketMQConstants;
import com.leyou.order.service.TbOrderService;
import com.leyou.seckill.dto.SecKillOrderDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.leyou.common.constants.RocketMQConstants.CONSUMER.SECKILL_ORDER_CONSUMER;
import static com.leyou.common.constants.RocketMQConstants.TAGS.SECKILL_ORDER_TAGS;
import static com.leyou.common.constants.RocketMQConstants.TOPIC.ORDER_TOPIC_NAME;

@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = SECKILL_ORDER_CONSUMER,
        topic = ORDER_TOPIC_NAME,
        selectorExpression = SECKILL_ORDER_TAGS)
public class SecKillCreateOrderListener  implements RocketMQListener<SecKillOrderDTO> {

    @Autowired
    private TbOrderService tbOrderService;
    /**
     * 接收消息，创建秒杀订单
     * @param secKillOrderDTO
     */
    @Override
    public void onMessage(SecKillOrderDTO secKillOrderDTO) {
        log.info("【订单服务】接收秒杀订单消息，secKillOrderDTO={}",secKillOrderDTO);
        tbOrderService.createSecKillOrder(secKillOrderDTO);
    }
}
